package com.company;

public class Main {

    public static void main(String[] args) {
	    System.out.println("你好");
        Foo foo1 = new Foo();

        Class c1 = Foo.class;
        Class c2 = foo1.getClass();

        //c1,c2 表示了Foo类的类类型
        //这个对象我们称为该类的类类型
        System.out.println(c1 ==c2);

        Class c3 = null;
        try {
            c3 = Class.forName("com.company.Foo");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println(c3 ==c2);

        //我们可以用类的类类型创建该类的对象类型
        try {
            Foo foo = (Foo)c1.newInstance();
            //需要有无参数的构造方法
            foo.print();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
class Foo{
    void print(){
        System.out.println("foo");
    }
}